package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.MenuManage;
import com.ruoyi.manage.service.IMenuManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 菜单管理Controller
 * 
 * @author yx
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/manage/manage")
public class MenuManageController extends BaseController
{
    @Autowired
    private IMenuManageService menuManageService;

    /**
     * 查询菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:list')")
    @GetMapping("/list")
    public AjaxResult list(MenuManage menuManage)
    {
        List<MenuManage> list = menuManageService.selectMenuManageList(menuManage);
        return success(list);
    }

    /**
     * 导出菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:export')")
    @Log(title = "菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuManage menuManage)
    {
        List<MenuManage> list = menuManageService.selectMenuManageList(menuManage);
        ExcelUtil<MenuManage> util = new ExcelUtil<MenuManage>(MenuManage.class);
        util.exportExcel(response, list, "菜单管理数据");
    }

    /**
     * 获取菜单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Integer menuId)
    {
        return success(menuManageService.selectMenuManageByMenuId(menuId));
    }

    /**
     * 新增菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:add')")
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuManage menuManage)
    {
        return toAjax(menuManageService.insertMenuManage(menuManage));
    }

    /**
     * 修改菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:edit')")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuManage menuManage)
    {
        return toAjax(menuManageService.updateMenuManage(menuManage));
    }

    /**
     * 删除菜单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage:remove')")
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Integer[] menuIds)
    {
        return toAjax(menuManageService.deleteMenuManageByMenuIds(menuIds));
    }
}
